var e = getApp();

Page({
    data: {},
    bindgetuserinfo: function (e) {
      var that = this;
      if (e.detail.userInfo) {
        // console.log(getApp().globalData.wechat_openid)
        // 发送 res.code 到后台换取 openId, sessionKey, unionId
        // var e = that;
        wx.login({
          success: function (o) {
            o.code ? wx.request({
              url: "https://api.zollo.cn/chss/index/openid",
              method: "POST",
              header: {
                "content-type": "application/json"
              },
              data: {
                code: o.code
              },
              success: function (o) {
                var n = this;
                (wx.setStorageSync("wechat_openid", o.data.openid),
                  getApp().globalData.wechat_openid = o.data.openid, wx.getUserInfo({
                    success: function (o) {
                      that.userInfo = o.userInfo, getApp().globalData.userInfoAll = o, that.userInfoReadyCallback && that.userInfoReadyCallback(o);
                      that.setData({ userInfo: o.userInfo});
                    }
                  }));
              }
            }) : console.log("获取用户登录态失败！" + o.errMsg);
          }
        });
      } else {
        console.log(333, '执行到这里，说明拒绝了授权')
        wx.showToast({
          title: "为了您更好的体验,请先同意授权",
          icon: 'none',
          duration: 2000
        });
      }
    },
    goInput: function() {
        wx.navigateTo({
            url: "../writeIn/writeIn"
        });
    },
    onLoad: function() {
        var t = this;
        if (wx.getStorageSync("wechat_openid")) {
            var o = {
                wechat_openid: wx.getStorageSync("wechat_openid")
            };
            // wx.request({
            //     url: "https://api.xiongmaomingli.com/api/index/user_info",
            //     data: o,
            //     method: "POST",
            //     success: function(e) {
            //         200 == e.statusCode && 200 == e.data.code && wx.navigateTo({
            //             url: "../detail/detail"
            //         });
            //     }
            // });
        } 
        // else wx.login({
        //     success: function(e) {
        //         e.code ? wx.request({
        //           url: "https://api.zollo.cn/chss/index/openid",
        //             method: "POST",
        //             header: {
        //                 "content-type": "application/json"
        //             },
        //             data: {
        //                 code: e.code
        //             },
        //             success: function(e) {
        //               if (200 == e.statusCode) {
        //                 console.log(e.data.openid)
        //                     wx.setStorageSync("wechat_openid", e.data.openid);
        //                     var t = {
        //                         wechat_openid: wx.getStorageSync("wechat_openid")
        //                     };
        //                     wx.request({
        //                         url: "https://api.xiongmaomingli.com/api/index/user_info",
        //                         data: t,
        //                         method: "POST",
        //                         success: function(e) {
        //                             200 == e.statusCode && 200 == e.data.code && wx.navigateTo({
        //                                 url: "../detail/detail"
        //                             });
        //                         }
        //                     });
        //                 }
        //             }
        //         }) : console.log("获取用户登录态失败！" + e.errMsg);
        //     }
        // })
        ;
        wx.showShareMenu({
            withShareTicket: !0
        }), wx.checkSession({
            success: function() {},
            fail: function() {}
        }), e.globalData.userInfo ? this.setData({
            userInfo: e.globalData.userInfo,
            hasUserInfo: !0
        }) : this.data.canIUse ? e.userInfoReadyCallback = function(e) {
            t.setData({
                userInfo: e.userInfo,
                hasUserInfo: !0
            });
        } : wx.getUserInfo({
            success: function(o) {
                e.globalData.userInfo = o.userInfo, t.setData({
                    userInfo: o.userInfo,
                    hasUserInfo: !0
                });
            }
        });
    },
    getUserInfo: function(e) {},
    onShareAppMessage: function(e) {
        return "button" === e.from && console.log(e.target), {
            path: "/pages/index/index",
            success: function(e) {
                console.log(e);
            },
            fail: function(e) {
                console.log(e);
            }
        };
    }
});